package com.jdzy.model.common.vos;

import lombok.Data;

@Data
public class ResultA<T> {


    //返回码
    private Integer code;

    //返回消息
    private String message;

    //返回数据
    private T data;

    public ResultA() {
    }

//    private static <T> ResultA<T> build(T data) {
//        ResultA<T> result = new ResultA<>();
//        if (data != null)
//            result.setData(data);
//        return result;
//    }
    public static <T> ResultA<T> build(T body, Integer code, String message) {
        ResultA<T> result = new ResultA<>();
        result.setData(body);
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

//    public static <T> ResultA<T> build(T body, ResultCodeEnum resultCodeEnum) {
//        ResultA<T> result = build(body);
//        result.setCode(resultCodeEnum.getCode());
//        result.setMessage(resultCodeEnum.getMessage());
//        return result;
//    }
public static <T> ResultA build(T body , ResultCodeEnum resultCodeEnum) {
    return build(body , resultCodeEnum.getCode() , resultCodeEnum.getMessage()) ;
}

    public static <T> ResultA<T> ok(T data) {
        return build(data, ResultCodeEnum.SUCCESS);
    }

    public static <T> ResultA<T> ok() {
        return ResultA.ok(null);
    }

    public static <T> ResultA<T> fail() {
        return build(null, ResultCodeEnum.FAIL);
    }
    public static <T> ResultA<T> fail(Integer code, String message) {
        ResultA result = new ResultA();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }


}
